<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Peserta_fix_model extends CI_Model {

    function __construct() {
        parent::__construct();
        $this->CI = get_instance();
    }

    function insert_peserta($data) {
        $this->db->insert('PESERTA', $data);
    }

    //list flexy
    function get_data_peserta($id_batch) {
        //Select table name
        $table_name = "PESERTA";

        //Build contents query
        $this->db->select('*')->from($table_name);
        $this->db->where("STATUS > 0 ");
        $this->db->where("STATUS_PESERTA > 0");
        $this->db->where("ID_BATCH", $id_batch);
        $this->CI->flexigrid->build_query();

        //Get contents
        $return['records'] = $this->db->get();

        //Build count query
        $this->db->select('*')->from($table_name);
        $this->db->where("STATUS > 0 ");
        $this->db->where("STATUS_PESERTA > 0");
        $this->db->where("ID_BATCH", $id_batch);
        $this->CI->flexigrid->build_query(FALSE);

        $return['record_count'] = $this->db->count_all_results();

        //Return all
        return $return;
    }
    
    
    //get data semua peserta fix
    function get_data_peserta_fix($id) {
        $this->db->select('*');
        $this->db->from('PESERTA');
        $this->db->where("STATUS > 0 ");
        $this->db->where("STATUS_PESERTA > 0");
        $this->db->where("ID_BATCH", $id);
        $query = $this->db->get();
        return $query;
    }
    
    
    function selectone($id) {
        $this->db->select('
		*,
		DAY(TANGGAL_LAHIR) as TANGGAL,
		MONTH(TANGGAL_LAHIR) as BULAN,
		YEAR(TANGGAL_LAHIR) as TAHUN,
		');
        $this->db->from('PESERTA');
        $this->db->where('ID_PESERTA', $id);
        $query = $this->db->get();
        return $query;
    }

    function update_status($id, $data) {
        $this->db->where('ID_PESERTA', $id);
        $this->db->update('PESERTA', $data);
    }

    function get_user() {
        $this->db->select("*");
        $this->db->from('USERS');
        $this->db->where("STATUS > 0 ");
        $query = $this->db->get();
        return $query;
    }

    function plot_kamar_cow($id) {
        $this->db->select('*');
        $this->db->from('PESERTA');
        $this->db->where("STATUS > 0 ");
        $this->db->where("STATUS_PESERTA > 0");
        $this->db->where("JENIS_KELAMIN", "L");
        $this->db->where("ID_BATCH", $id);
        //$this->db->order_by('JENIS_KELAMIN');
        $query = $this->db->get();
        return $query;
    }

    function plot_kamar_cew($id) {
        $this->db->select('*');
        $this->db->from('PESERTA');
        $this->db->where("STATUS > 0 ");
        $this->db->where("STATUS_PESERTA > 0");
        $this->db->where("JENIS_KELAMIN", "P");
        $this->db->where("ID_BATCH", $id);
        //$this->db->order_by('JENIS_KELAMIN');
        $query = $this->db->get();
        return $query;
    }

    function save_plot_kamar($data) {
        $this->db->insert('KAMAR', $data);
    }

    //get data kamar peserta
    function get_data_kamar($id) {
        $this->db->select('*');
        $this->db->from('KAMAR');
        //$this->db->where("STATUS > 0 ");
        //$this->db->where("STATUS_PESERTA > 0");
        $this->db->where("ID_BATCH", $id);
        //$this->db->order_by('JENIS_KELAMIN');
        $query = $this->db->get();
        return $query;
    }
    
    function delete_kamar($id_batch) {
        $this->db->where('ID_BATCH', $id_batch);
        $this->db->delete('KAMAR');
    }
    
    
    function insert_alumni($data) {
        $this->db->insert('ALUMNI', $data);
    }

    function get_lisensi($id) {
        $this->db->select('ID_LISENSI');
        $this->db->from('BATCH');
        $this->db->where("ID_BATCH", $id);
        $query = $this->db->get();
        return $query;
    }

    function get_alumni($email) {
        $this->db->select('*');
        $this->db->from('ALUMNI');
        $this->db->where("EMAIL", $email);
        $query = $this->db->get();
        return $query;
    }

}

?>